package com.xxr.mom.ci.api.component.interceptor;

import com.xxr.mom.ci.common.log.LogTrace;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import lombok.extern.log4j.Log4j2;
import org.apache.logging.log4j.ThreadContext;
import org.springframework.context.annotation.Configuration;

@Log4j2
@Configuration
public class OpenFeignInterceptor implements RequestInterceptor {

    @Override
    public void apply(RequestTemplate requestTemplate) {
        try {
            requestTemplate.header(LogTrace.TRACE_ID, ThreadContext.get(LogTrace.TRACE_ID));
            requestTemplate.header(LogTrace.TRACE_ORDER, (Integer.parseInt(ThreadContext.get(LogTrace.TRACE_ORDER)) + 1) + "");
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }


}